﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using OnlineStore.Bll;
using OnlineStore.Dal;

namespace OnlineStore.Gui
{
    public partial class ProductDetail : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            string ID = Request.QueryString.Get("id");
            bizProduct _bizproduct = new bizProduct();
            tbProduct _product = _bizproduct.SearchPorduct(ID);
            if (_product == null)
                Product_find.Visible = true;
            else
            {
                lb_Title.Text = _product.Product_Name;
                //string img = "../img/" + _product.Picture;
                //img = img.Trim();
                //HL_Img_product.NavigateUrl = img;
                //Image_product.ImageUrl = img;
                 HL_Img_product.NavigateUrl ="/Bll/ImageHttpHandler.ashx?id=2";
                 Image_product.ImageUrl = "/Bll/ImageHttpHandler.ashx?id=2";
                lb_price.Text = String.Format("{0:0,0 VNĐ}", _product.Price);
                if (_product.Stock_Qty >= 1)
                    lb_Status.Text = "Còn " + bizProduct.Stock(_product);
                else
                    lb_Status.Text = "Hết Hàng";
                lb_Type.Text = _product.Type;
                lb_Color.Text = _product.Color;
                lb_Introduce.Text = _product.Introduce;
                lb_Detail.Text = _product.Detail;

                if (Session["user"] != null)
                {
                    HL_tab_login.NavigateUrl = "/gui/Account.aspx";
                    HL_tab_login.Text = ((tbCustomer)Session["user"]).Username;
                    HL_tab_Logout.Visible = true;
                }
            }
            DalProduct _DalProduct = new DalProduct();
            mainlist.DataSource = _DalProduct.Outstanding();
            mainlist.DataBind();
            ListCartRight.DataSource = (List<bizCart>)Session["cart"];
            ListCartRight.DataBind();
            lb_Sum.Text = String.Format("{0:0,0 VNĐ}", bizCart.SumAllList((List<bizCart>)Session["cart"]));
            lb_Sum_product.Text = String.Format("{0:0,0 VNĐ}", bizCart.SumAllList((List<bizCart>)Session["cart"]));
        }

        protected void Lick_Mua(object sender, EventArgs e)
        {
            bizCart _bizCart = new bizCart();
            bizProduct _bizProduct = new bizProduct();
            Session["cart"] = _bizCart.addToCart((List<bizCart>)Session["cart"],Request.QueryString.Get("id"),this.Qty.Text);
            ListCartRight.DataSource = (List<bizCart>)Session["cart"];
            ListCartRight.DataBind();
            lb_Sum.Text = String.Format("{0:0,0 VNĐ}", bizCart.SumAllList((List<bizCart>)Session["cart"]));
            lb_Sum_product.Text = String.Format("{0:0,0 VNĐ}", bizCart.SumAllList((List<bizCart>)Session["cart"]));
            
        }
    }
}